#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

LL a,b,mod;
int main(){
	scanf("%lld%lld%lld",&a,&b,&mod);
	LL a1=a,b1=b;
	LL ans=1L;
	LL base=a;
	while(b>0){
		if(b&1){
			ans=ans*base%mod;
		}
		base=(base*base)%mod;
		b/=2;
	}
	printf("%lld^%lld mod %lld=%lld",a1,b1,mod,ans);
	return 0;
}
